package com.andy;

import lombok.extern.slf4j.Slf4j;
import org.activiti.engine.ProcessEngine;
import org.activiti.engine.ProcessEngines;
import org.activiti.engine.RuntimeService;
import org.activiti.engine.runtime.ProcessInstance;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

@Slf4j
@RunWith(SpringRunner.class)
@SpringBootTest
public class BusinessKey {

    @Test
    public void addBusinessKey(){
        //1、获取流程引擎
        ProcessEngine  processEngine = ProcessEngines.getDefaultProcessEngine();
        //2、创建RunTimeService
        RuntimeService runtimeService = processEngine.getRuntimeService();
        //3、启动流程的过程中，添加businessKey
        /**
         * 第一个参数：BPMN文件的process-id
         * 第二个参数： 自己定义的businessKey(业务ID)
         */
        ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("workOrder", "Key2");
        //4、输出
        System.out.println("BusinessKey: "+processInstance.getBusinessKey());
    }
}
